package com.haixiaoke.saas.enterprise.house.controller;

import com.haixiaoke.saas.common.annotation.RepeatSubmit;
import com.haixiaoke.saas.common.annotation.TenantScope;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.tenant.TenantContext;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.house.domain.HouseChargeItem;
import com.haixiaoke.saas.house.service.IHouseChargeItemService;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 房屋收费项目Controller
 *
 * @author xiaolong
 * @date 2023-11-25
 */
@RestController
@RequestMapping("/enterprise/house/houseChargeItem")
public class EnterpriseHouseChargeItemController extends BaseController {
    @Autowired
    private IHouseChargeItemService houseChargeItemService;

    /**
     * 查询房屋收费项目列表
     */
    @PreAuthorize("@ss.hasPermi('business:item:list')")
    @GetMapping("/list")
    @TenantScope
    public TableDataInfo list(HouseChargeItem houseChargeItem) {
        startPage();
        houseChargeItem.setTenantId(TenantContext.getTenantId());
        List<HouseChargeItem> list = houseChargeItemService.selectHouseChargeItemList(houseChargeItem);
        return getDataTable(list);
    }

    /**
     * 导出房屋收费项目列表
     */
    @PreAuthorize("@ss.hasPermi('business:item:export')")
    @PostMapping("/export")
    @TenantScope
    public void export(HttpServletResponse response, HouseChargeItem houseChargeItem) {
        houseChargeItem.setTenantId(TenantContext.getTenantId());
        List<HouseChargeItem> list = houseChargeItemService.selectHouseChargeItemList(houseChargeItem);
        ExcelUtil<HouseChargeItem> util = new ExcelUtil<HouseChargeItem>(HouseChargeItem.class);
        util.exportExcel(response, list, "房屋收费项目数据");
    }

    /**
     * 获取房屋收费项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:item:query')")
    @GetMapping(value = "/{chargeItemId}")
    public AjaxResult getInfo(@PathVariable("chargeItemId") Long chargeItemId) {
        return success(houseChargeItemService.selectHouseChargeItemByChargeItemId(chargeItemId));
    }

    /**
     * 新增房屋收费项目
     */
    @PreAuthorize("@ss.hasPermi('business:item:add')")
    @PostMapping
    @TenantScope
    @RepeatSubmit
    public AjaxResult add(@RequestBody HouseChargeItem houseChargeItem) {
        houseChargeItem.setTenantId(TenantContext.getTenantId());
        return toAjax(houseChargeItemService.insertHouseChargeItem(houseChargeItem));
    }

    /**
     * 修改房屋收费项目
     */
    @PreAuthorize("@ss.hasPermi('business:item:edit')")
    @PutMapping
    @TenantScope
    @RepeatSubmit
    public AjaxResult edit(@RequestBody HouseChargeItem houseChargeItem) {
        return toAjax(houseChargeItemService.updateHouseChargeItem(houseChargeItem));
    }

    /**
     * 删除房屋收费项目
     */
    @PreAuthorize("@ss.hasPermi('business:item:remove')")
    @DeleteMapping("/{chargeItemIds}")
    @TenantScope
    @RepeatSubmit
    public AjaxResult remove(@PathVariable Long[] chargeItemIds) {
        return toAjax(houseChargeItemService.deleteHouseChargeItemByChargeItemIds(chargeItemIds));
    }

    /**
     * 查询房屋收费项目列表
     */
    @PreAuthorize("@ss.hasPermi('business:item:list')")
    @GetMapping("/allInfo")
    @TenantScope
    public AjaxResult allInfo(HouseChargeItem houseChargeItem) {
        houseChargeItem.setTenantId(TenantContext.getTenantId());
        List<HouseChargeItem> list = houseChargeItemService.selectHouseChargeItemList(houseChargeItem);
        return success(list);
    }
}
